package com.cgc.venus.server.app.controller;

import com.cgc.venus.server.app.bean.AppType;
import com.cgc.venus.server.app.bean.StoreApp;
import com.cgc.venus.server.app.inter.AppStoreService;
import com.cgc.venus.server.core.bean.response.VenusResponse;
import com.cgc.venus.server.core.bean.response.VenusResponseStatus;
import com.cgc.venus.server.core.exception.VenusException;
import com.cgc.venus.server.core.harbor.model.Tag;
import io.swagger.annotations.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

/**
 * Created by 业哥 on 2017/6/3.
 */
@Api(value = "应用商店", description = "应用商店所对应服务的api")
@RequestMapping("/store-admin")
@RestController
public class AppStoreController {
    @Autowired
    private AppStoreService appStoreServiceImpl;
    @ApiOperation("应用类型查询")
    @RequestMapping(value = "/app-type", method = RequestMethod.GET)
    public VenusResponse<Object> appTypeQuery(@RequestParam(value = "queryKey", required = false) String queryKey) throws VenusException {
        List<Map<String, Object>> obj = appStoreServiceImpl.appTypeQuery(queryKey);
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"",obj);
        return response;
    }

    @ApiOperation("应用类型新增")
    @RequestMapping(value = "/app-type", method = RequestMethod.POST)
    public VenusResponse<Object> appTypeAdd(@RequestBody AppType appType) throws VenusException {
        Boolean obj = appStoreServiceImpl.appTypeAdd(appType.getType(),appType.getDesc());
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"新增成功",obj);
        return response;
    }

    @ApiOperation("应用类型修改")
    @RequestMapping(value = "/app-type", method = RequestMethod.PATCH)
    public VenusResponse<Object> appTypeUpdate(@RequestBody AppType appType) throws VenusException {
        Boolean obj = appStoreServiceImpl.appTypeUpdate(appType.getId(),appType.getType(),appType.getDesc());
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"修改成功",obj);
        return response;
    }

    @ApiOperation("应用类型删除")
    @RequestMapping(value = "/app-type/{id}", method = RequestMethod.DELETE)
    public VenusResponse<Object> appTypeDelete(@PathVariable(value = "id") String id) throws VenusException {
        Boolean obj = appStoreServiceImpl.appTypeDelete(id);
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"删除成功",obj);
        return response;
    }

    @ApiOperation("商店应用查询(未上架应用)")
    @RequestMapping(value = "/store-app/un-ground", method = RequestMethod.GET)
    public VenusResponse<Object> appQuery0(@RequestParam(value = "queryKey", required = false) String queryKey) throws VenusException {
        List<Map<String, Object>> obj = appStoreServiceImpl.appQueryOnGround(queryKey);
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"",obj);
        return response;
    }
    @ApiOperation("商店应用查询(上架应用)")
    @RequestMapping(value = "/store-app/ground", method = RequestMethod.GET)
    public VenusResponse<Object> appQuery1(@RequestParam(value = "queryKey", required = false) String queryKey,@RequestParam(value = "appType", required = false) String appType) throws VenusException {
        List<Map<String, Object>> obj = appStoreServiceImpl.appQueryGround(queryKey,appType);
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"",obj);
        return response;
    }

    @ApiOperation("商店应用新增")
    @RequestMapping(value = "/store-app", method = RequestMethod.POST)
    public VenusResponse<Object> appStoreAdd(@RequestBody StoreApp storeApp) throws VenusException {
        Boolean obj = appStoreServiceImpl.appAdd(storeApp.getName(),storeApp.getAppType(),storeApp.getDesc());
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"新增成功",obj);
        return response;
    }
    @ApiOperation("商店应用删除(未上架应用)")
    @RequestMapping(value = "/store-app/un-ground", method = RequestMethod.DELETE)
    public VenusResponse<Object> appStoreDelete0(@RequestBody StoreApp storeApp) throws VenusException {
        Boolean obj = appStoreServiceImpl.appUnGroundDelete(storeApp.getName());
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"删除成功",obj);
        return response;
    }

    @ApiOperation("商店应用删除(下架)")
    @RequestMapping(value = "/store-app", method = RequestMethod.DELETE)
    public VenusResponse<Object> appStoreDelete1(@RequestBody StoreApp storeApp) throws VenusException {
        Boolean obj = appStoreServiceImpl.appDelete(storeApp.getIds());
        VenusResponse<Object> response=new VenusResponse<Object>(VenusResponseStatus.OK,"删除成功",obj);
        return response;
    }
}